import random
name=['A','B','C','D','E','F','G','H']
room=[[],[],[]]
therest=[]
#遍历名称，写入到空房间，如果房间分配的个数小于3则写入，其他的添加到一个新数列，留后续分配
for i in name:
    j=random.randint(0,2)
    if len(room[j])<3:
        room[j].append(i)
    else:
        therest.append(i)
#1.判断therest是否为空，若为空停止while,若不为空，继续循环
#2.每次不为空，就写入room[0-2]，要先判断是否>3
#3.循环后，remove掉，第0个
print(room)
print(therest)
while len(therest)!=0:
    g=random.randint(0,2)
    if len(room[g])<3:
        room[g].append(therest[0])
        therest.pop(0)
print(room)
#遍历打印出分配好的列表
a=1
for office in room:
    print(f'the no. of {a}:',end=' ')
    for pe in office:
        print(pe,end=' ')
    a+=1
    print()